/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.tbp.gui.table;

import br.com.tbp.model.domain.Endereco;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Diego
 */
public class EnderecoTableModel extends AbstractTableModel {

    private List<Endereco> enderecoList;

    public EnderecoTableModel(List<Endereco> lista) {
        this.enderecoList = lista;
    }

    public EnderecoTableModel() {
        this.enderecoList = new ArrayList<Endereco>();
    }

    public int getRowCount() {
        return enderecoList.size();
    }

    public int getColumnCount() {
        return 5;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
                return String.class;
        }
        return Object.class;
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Logradouro";
            case 1:
                return "Bairro";
            case 2:
                return "Cidade";
            case 3:
                return "Estado";
            case 4:
                return "CEP";
        }
        return null;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Endereco endereco = this.getEndereco(rowIndex);
        if (endereco != null) {
            switch (columnIndex) {
                case 0:
                    return endereco.getLougradouro();
                case 1:
                    return endereco.getBairro();
                case 2:
                    return endereco.getCidade();
                case 3:
                    return endereco.getEstado();
                case 4:
                    return endereco.getCep();
            }
        }
        return null;
    }

    public Endereco getEndereco(int row) {
        if (row >= 0) {
            return enderecoList.get(row);
        }
        return null;
    }
}
